﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Xml;

namespace Constructor.Frames
{
    public class NewItem:Object
    {
        private List<string> _collection = new List<string>();
        public List<string> Collection 
        { get
          {
          	return _collection.AsReadOnly().ToList();
          }
        }
        public void Add(string item)
        {
            _collection.Add(item);
        }
        public void AddRange(IEnumerable<string> range)
        {
            _collection.AddRange(range);
        }
        public void AddRange(NewItem item)
        {
            _collection.AddRange(item.Collection);
        }
        public NewItem(Slot slot)
        {
            Content = slot;
        }
        public string this[int i] 
        {
            get
            {
                return _collection[i];
            }            
        }
        public int Count
        {
            get
            {
                return _collection.Count;
            }
        }
        public string Text
        {
            get
            {
                return ToString();
            }
        }
        public Slot Content { get; set; }
        public NewItem(string item, Slot slot)
        {
            Add(item);
            Content = slot;
        }
        public override string ToString()
        {           
            string result = string.Empty;
            if (Count == 1)
                return this[0];
            else
            {
                try
                {
                    Frame f = External.SearchFrame(this[0]);
                    result += f.Name;
                    for (int i = 1; i < Count; i++)
                    {
                        Slot s = f.SearchInAllSlot(this[i]);
                        result +="." + s.Name;
                        f = s.Subframe;
                    }
                }
                catch
                {
                    //Trace.Fail("Не удалось сформировать тест NewItem");
                }
                return result;
            }            
        }
        public NewItem Clone()
        {
            NewItem result = new NewItem(Content);
            result.AddRange(this);
            return result;
        }
    }
}
